import util from "@/libs/util.js";
export const crudOptions = (vm) => {
	// 验证路由地址
	const validateWebPath = (rule, value, callback) => {
		const isLink = vm.getEditForm().is_link;
		let pattern = /^\/.*?/;
		if (isLink) {
			pattern = /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/g;
		} else {
			pattern = /^\/.*?/;
		}
		if (!pattern.test(value)) {
			callback(new Error("请正确的地址"));
		} else {
			callback();
		}
	};
	return {
		// pagination: false,
		pageOptions: {
			compact: true,
		},
		options: {
			tableType: "vxe-table",
			rowKey: true, // 必须设置，true or false
			rowId: "id",
			height: "100%", // 表格高度100%, 使用toolbar必须设置
			highlightCurrentRow: false,
		},
		rowHandle: {
			view: {
				show: false,
				disabled() {
					return !vm.hasPermissions("Retrieve");
				},
			},
			width: 240,
			edit: {
				thin: true,
				text: "编辑",
				disabled() {
					return !vm.hasPermissions("Update");
				},
			},
			remove: {
				thin: true,
				text: "删除",
				disabled() {
					return !vm.hasPermissions("Delete");
				},
			},
		},
		formGroup: {
			groups: {
				base: {
					title: "基础信息",
					columns: [
						"head_portrait",
						"qr_code",
						"name",
						"account_number",
						"original_id",
						"status",
					],
				},
				material: {
					title: "账号管理",
					columns: [
						"account_type",
						"appid",
						"app_secret",
						"url",
						"token",
						"encoding_aes_key",
					],
				},
			},
		},
		indexRow: {
			// 或者直接传true,不显示title，不居中
			title: "序号",
			align: "center",
			width: 100,
		},

		viewOptions: {
			componentType: "form",
		},
		/* 	formOptions: {
			defaultSpan: 24, // 默认的表单 span
			width: "35%",
			saveRemind: true,
		}, */
		formOptions: {
			defaultSpan: 12, // 默认的表单 span
		},
		columns: [
			{
				title: "关键词",
				key: "search",
				show: false,
				disabled: true,
				search: {
					disabled: false,
				},
				form: {
					disabled: true,
					component: {
						placeholder: "请输入关键词",
						props: {
							clearable: true,
						},
					},
				},
				view: {
					// 查看对话框组件的单独配置
					disabled: true,
				},
			},
			{
				title: "ID",
				key: "id",
				show: false,
				width: 90,
				form: {
					disabled: true,
				},
			},
			{
				title: "头像",
				key: "head_portrait",
				minWidth: 160,
				type: "avatar-uploader",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
				},
				/* form: {
					valueChange(key, value, form, context) {
						console.log("avatar chagned", key, value);
					},
					rules: [
						{
							// 当有文件还未上传完成时，阻止表单提交，等待全部上传完成，才允许提交
							validator:
								D2pFileUploader.createAllUploadedValidator(
									vm.getFormComponentRef
								),
							message:
								"还有文件正在上传，请等待上传完成，或删除它",
						},
					],
				}, */
			},

			{
				title: "二维码",
				key: "qr_code",
				minWidth: 160,
				type: "avatar-uploader",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
				},
				/* form: {
					valueChange(key, value, form, context) {
						console.log("avatar chagned", key, value);
					},
					rules: [
						{
							// 当有文件还未上传完成时，阻止表单提交，等待全部上传完成，才允许提交
							validator:
								D2pFileUploader.createAllUploadedValidator(
									vm.getFormComponentRef
								),
							message:
								"还有文件正在上传，请等待上传完成，或删除它",
						},
					],
				}, */
			},

			{
				title: "公众号名称",
				key: "name",
				minWidth: 130,
				type: "input",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						placeholder: "请输入公众号名称",
					},
				},
			},
			{
				title: "公众号账号",
				key: "account_number",
				minWidth: 130,
				type: "input",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						placeholder: "请输入公众号账号",
					},
				},
			},
			{
				title: "原始ID",
				key: "original_id",
				minWidth: 90,
				type: "input",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						placeholder: "请输入原始ID",
					},
				},
			},

			{
				title: "状态",
				key: "status",
				sortable: true,
				width: 100,
				type: "radio",
				dict: {
					data: [
						{
							value: 0,
							label: "禁用",
						},
						{
							value: 1,
							label: "启用",
						},
					],
				},
				form: {
					value: 0,
					component: {
						placeholder: "请选择状态",
					},
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
				},
			},
			{
				title: "账号类型",
				key: "account_type",
				minWidth: 180,
				type: "select",
				dict: {
					data: [
						{
							value: 1,
							label: "认证服务号",
						},
						{
							value: 2,
							label: "认证媒体",
						},
						{
							value: 3,
							label: "政府订阅号",
						},
						{
							value: 4,
							label: "个人",
						},
					],
				},
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						placeholder: "请选择类型",
					},
				},
			},

			{
				title: "Appid",
				key: "appid",
				minWidth: 130,
				type: "input",
				disabled: true,
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						placeholder: "请输入Appid",
					},
				},
			},
			{
				title: "AppSecret",
				key: "app_secret",
				minWidth: 130,
				disabled: true,
				type: "input",
				form: {
					rules: [
						// 表单校验规则
						{ required: true, message: "状态必填项" },
					],
					component: {
						showPassword: true,
						placeholder: "请输入AppSecret",
					},
				},
			},
			{
				title: "服务器地址",
				key: "url",
				minWidth: 130,
				disabled: true,
				type: "input",
				form: {
					value: util.baseURL(),
					component: {
						disabled: true,
						placeholder: "请输入服务器地址",
					},
				},
			},
			{
				title: "令牌",
				key: "token",
				disabled: true,
				minWidth: 130,
				form: {
					component: {
						showPassword: true,
						rules: [
							// 表单校验规则
							{ required: true, message: "状态必填项" },
						],
						placeholder: "请输入令牌",
					},
				},
			},
			{
				title: "消息加解密秘钥",
				key: "encoding_aes_key",
				minWidth: 130,
				disabled: true,
				type: "input",
				form: {
					component: {
						showPassword: true,
						rules: [
							// 表单校验规则
							{ required: true, message: "状态必填项" },
						],
						placeholder: "请输入消息加解密秘钥",
					},
				},
			},
		],
	};
};
